﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Manage/Views/Shared/Site.Master"
    Inherits="System.Web.Mvc.ViewPage<QianBuo.Lottery.Web.Models.User.PlayTypeOptionModel>" %>

<%@ Import Namespace="Code.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    奖金设置
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="StyleAndScript" runat="server">
    <style type="text/css">
        .table td, .table th
        {
            padding: 3px 0px;
        }
        input[type='checkbox']
        {
            margin: 1px;
        }
        .validation_summary_div ul
        {
            float: left;
            overflow: hidden;
            height: auto;
        }
        .validation_summary_div li
        {
            float: left;
            overflow: hidden;
            height: auto;
            width: 235px;
            line-height: 21px;
            text-align: left;
            list-style-type: decimal;
            list-style-position: inside;
            font-weight: normal;
            font-family: Arial;
            font-size: 12px;
        }
    </style>
    <script src='<%=Url.Content("~/Scripts/jquery.metadata.js") %>' type="text/javascript"></script>
    <script type="text/javascript">
        var url = '<%=Url.Action("SetWinMoney", new { id="",act=Request["act"],cont=Request["cont"],returnurl=Request["returnurl"],Model.Uid})%>';
        function ddlChage(o) {
            document.location.href = url + '&id=' + o.value;
        }
        $(document).ready(function () {
            var str = null;
            $("#optionform").validate();
            $("#optionform .table input[validate]").each(function () {
                $(this).parent().css("text-align", "left");
            });
            $("input[ckmodelid]").click(function () {
                var item = this;
                var ckmodelid = $(this).attr("ckmodelid");
                $("." + ckmodelid + " :checkbox").each(function () {
                    this.checked= item.checked;
                });
            });
            $("input[modelid]").change(function () {
                var item = $(this);
                var modelid = item.attr("modelid");
                str = item.attr("cktype");
                var cktype = null;
                if (str != undefined) {
                    cktype = eval("(" + str + ")");
                }
                var num = _ParseDouble(this.value);
                if (num == null || num < 0)
                    return;
                else {
                    $("." + modelid + " :text").each(function () {
                        if (cktype != null) {
                            str = $(this).attr("playtype");
                            var flag = false;
                            for (var i in cktype.play) {
                                var item = cktype.play[i];
                                if (item == str) {
                                    flag = true;
                                    break;
                                }
                            }
                            if ((flag == true && cktype.contain == true) || (cktype.contain == false && flag == false)) {
                                this.value = num;
                            }
                        } else {
                            var tp = _ParseDouble($(this).attr("oldvalue"));
                            str = num.div(100).mul(tp);
                            this.value = str;
                        }
                        $(this).valid();
                    });
                }
            }).keypress(function (e) {
                if (e.keyCode == 13) {
                    e.keyCode = 9;
                    this.blur();
                    return false;
                }
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <% Html.DisableClientValidation(); %>
        <% Html.BeginForm(new { id = "optionform" }, new { lottery = Model.LotteryID }); %>
        <fieldset>
            <legend>[<%=Model.UserName %>]奖金设置</legend>
            <% if (Request["returnUrl"] != null) %>
            <% { %>
            <a href='<%=Request["returnUrl"] %>' class="a_blue">&gt;&gt;返回</a> |
            <% } %>
            <div style="width: 100%; height:30px;margin-top:10px;">
                <div style="height: 20px; text-align:left; float:left">
                    <%=Html.ActionLink("与下级(奖金)差调整", "SubWinMoneyMargin", new { ID = Model.Uid ,act="SetWinMoney",ReturnUrl=Request["ReturnUrl"] }, new { @class = "a_blue" })%></div>
                <div style="height: 20px; text-align:right">
                    <%=Html.ActionLink("返点设置", "SetWinRatio", new { uid = Model.Uid,returnurl=Request.RawUrl }, new { @class="a_blue"})%></div>
            </div>
            <table class="table" width="100%">
                <%
                    var groupwin = Model.Options.GroupBy(p => new { Name = p.WinMoneyName, ID = p.Option.WinMoneyModelID });
                    var wins = groupwin.Select(p => p.Key).OrderBy(p => p.ID).ToArray();
                %>
                <tr>
                    <th rowspan="2">
                        <%=Html.DropDownListFor(p => p.LotteryID, Model.Lotterys.Select(p => new SelectListItem { Text = p.Value, Value =p.Key.ToString(), Selected = Model.LotteryID.HasValue ? p.Key == Model.LotteryID : false }), new { onchange = "ddlChage(this)" })%>
                    </th>
                    <% foreach (var item in wins) %>
                    <% { %>
                    <th colspan='2'>
                        <%=item.Name %>
                    </th>
                    <% } %>
                </tr>
                <tr>
                    <% foreach (var item in wins) %>
                    <% { %>
                    <th colspan="2">
                        <%if (Model.UseSiteWinMoney) %>
                        <% { %>
                        <font color="red">站点的奖金</font>
                        <% } %>
                        <% else %>
                        <% { %>
                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <input type="checkbox" title="全选" ckmodelid='<%=item.ID + "WinMoney" %>' />奖金<input
                            type="text" class="text40" value="100" modelid='<%=item.ID + "WinMoney" %>' validate="{number:true,min:0,messages:{number:'*',min:'>=0'}}" />%
                        <% } %>
                    </th>
                    <% } %>
                </tr>
                <% var single = groupwin.First().OrderBy(p => p.Option.BackMoneyTypeID).OrderBy(p => p.PlaySort).Select(p => new { p.PlayName, p.Option.PlayTypeID, p.Option.WinMoneyModelID }); %>
                <% foreach (var pl in single)%>
                <% { %>
                <tr>
                    <td>
                        <%=pl.PlayName%>
                    </td>
                    <% foreach (var win in wins)%>
                    <% { %>
                    <% var i = Array.FindIndex(Model.Options, p => p.Option.PlayTypeID == pl.PlayTypeID && p.Option.WinMoneyModelID == win.ID); %>
                    <% var item = Model.Options[i]; %>
                    <td class='<%=win.ID + "WinMoney"%>' title='上级的奖金:<%=item.CurrentWimMoney %>' colspan="2">
                        <%=Html.HiddenFor(p=>p.Options[i].Option.PlayTypeID) %>
                        <%=Html.HiddenFor(p=>p.Options[i].Option.WinMoneyModelID) %>
                        <%if (Model.UseSiteWinMoney) %>
                        <% { %>
                        <%=item.Option.WinMoney %>
                        <% } %>
                        <% else %>
                        <% { %>
                        <%=Html.CheckBoxFor(p => p.Options[i].Option.ResetWinMoney, new { title = "重置所有下级" }) %>
                        <%=Html.TextBoxFor(p => p.Options[i].Option.WinMoney, new { @class = "text50", playtype = item.Option.PlayTypeListID, oldvalue = item.Option.WinMoney, validate = string.Format("{{required:true,number:true,min:{0},max:{1},messages:{{required:'*',number:'*',min:'>={0}',max:'<={1}'}}}}", item.MinWinMoney, item.CurrentWimMoney) })%>
                        <%=Html.HiddenFor(p=>p.Options[i].Option.BackMoneyRatio) %>
                        <%=Html.ValidationMessageFor(p=>p.Options[i].Option.WinMoney) %>
                        <% } %>
                    </td>
                    <% } %>
                </tr>
                <% } %>
                <tr>
                    <td colspan="7">
                        <input type="submit" value="保存"   <%=ViewData["btnAddDisabled"]!=null&&((bool)ViewData["btnAddDisabled"])?"disabled='disabled'":"" %> onclick="return confirm('确定提交吗？')" />&nbsp;&nbsp;
                        <input type="reset" value="重设" />
                    </td>
                </tr>
            </table>
        </fieldset>
        <%=Html.HiddenFor(p=>p.Uid) %>
        <%=Html.SerializableFor(p=>p.Lotterys) %>
        <%Html.EndForm(); %>
    </div>
</asp:Content>
